package org.test.jspdb.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.test.jspdb.manager.UserManager;
import org.test.jspdb.model.User;
import org.test.jspdb.utils.JqueryProcess;
import org.test.jspdb.utils.Page;

/**
 * 
 * @author cennanfang
 * @date 2013-7-22
 * @fileName UserServlet.java
 */
public class UserServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	private int page;
	private int rows;
	private String[] ids;
	private String flag;

	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("GB2312");
		
		System.out.println(req.getParameter("rows"));
		System.out.println(req.getParameter("page"));

		UserManager userManager = new UserManager();
		
		List<User> users = userManager.searchUsers();
		Page dataPage = new Page(users, users.size());
		JqueryProcess.processReturnJson(resp, dataPage);
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public String[] getIds() {
		return ids;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}
}
